package cn.bxshey.general.Result;

import cn.bxshey.general.enums.ResultEnum;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @作者：不想说话而已
 * @Date：2023/11/28 9:36
 */
@Data
public class Result<T> {
    @NotBlank
    @NotNull
    Integer code; //响应状态码

    @NotBlank
    @NotNull
    String msg; //响应信息

    T data; //返回的主体内容

    Result(ResultEnum success) {
        this.code = success.code;
        this.msg = success.msg;
    }

    Result() {
    }

    public static <T> Result<T> success() {
        return new Result<T>(ResultEnum.SUCCESS);
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<T>(ResultEnum.SUCCESS);
        result.data = data;
        return result;
    }

    public static <T> Result<T> error() {
        return new Result<T>(ResultEnum.ERROR);
    }

    public static <T> Result<T> error(ResultEnum resultEnum) {
        return new Result<T>(resultEnum);
    }

    public static <T> Result<T> error(Integer code,String msg) {
        Result<T> tResult = new Result<>();
        tResult.setCode(code);
        tResult.setMsg(msg);
        return tResult;
    }


}
